package safari.controller.common;

import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.multiaction.MultiActionController;

import safari.model.common.CommonService;
/**
 * 일반적인 서비스를 담당하는 CommonController 클래스
 * @author kosta-00-01
 *
 */
public class CommonController extends MultiActionController {
	private CommonService commonService;
	/**
	 * CommonController 생성자
	 * CommonService 객체를 주입받아서 commonService를 사용한다.
	 */
	public CommonController(CommonService commonService){
		this.commonService=commonService;
	}
	/**
	 * 메인 페이지를 보여주는 메서드
	 * 메인 페이지는 최근 게시판들을 보여준다.
	 * @throws SQLException 
	 */
	public ModelAndView moveToMain(HttpServletRequest request, HttpServletResponse response) throws SQLException{
		Map boardListInfo=new HashMap();
		boardListInfo=commonService.moveToMain();
		return new ModelAndView("main_test","boardListInfo",boardListInfo);
	}
	/**
	 * 메인페이지로 가는 역할
	 * 
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 */
	public ModelAndView home(HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		Map boardListInfo=new HashMap();
		boardListInfo=commonService.moveToMain();
		return new ModelAndView("home","boardListInfo",boardListInfo);
	}
	
}
